/*
 *  Arrow
 *
 *  Created by David Giovannini on 1/5/07.
 *  Copyright 2007 Software by Jove. All rights reserved.
 *
 */
 
#include "SBJ/Arrow/PublicationMgr.h"

namespace SBJ
{

namespace Arrow
{

PublicationMgr::PublicationMgr( const IExceptionObserver::Ptr& excObserver )
: m_excObserver( excObserver )
{
}

PublicationMgr::~PublicationMgr( void )
{
	KeyedPublications::iterator iter( m_publications.begin() );
	while ( iter != m_publications.end() )
	{
		delete iter->second;
		++iter;
	}
}

Publication*
PublicationMgr::findPublication( const std::string& pubKey ) const
{
	boost::mutex::scoped_lock lock( m_publicationGuard );
	KeyedPublications::const_iterator findPub = m_publications.find( pubKey );
	if ( findPub != m_publications.end() )
	{
		return findPub->second;
	}
	return 0;
}

Topic
PublicationMgr::makeTopic( const std::string& pubKey, const std::string& topicKey )
{
	Publication* pub = findPublication( pubKey );
	if ( pub != 0 )
	{
		return pub->makeTopic( topicKey );
	}
	return Topic();	
}

Topic
PublicationMgr::getTopic( const std::string& pubKey, const std::string& topicKey ) const
{	
	Publication* pub = findPublication( pubKey );
	if ( pub != 0 )
	{
		return pub->getTopic( topicKey );
	}
	return Topic();	
}

}

}

